package com.xinyu.qmdbl.wan51.wxapi;

import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.wan.commonsdk.Conet;
import com.wan.commonsdk.Keys;
import com.wan.commonsdk.WanCommonSdk;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

	private IWXAPI api;

	@Override
	public void onCreate(Bundle

	savedInstanceState) {
		super.onCreate(savedInstanceState);
		api = WXAPIFactory.createWXAPI(this, Keys.getWXAppID());

		api.handleIntent(getIntent(), this);

	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);

		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		String orderid = Conet.TrackingIOSP.getString("orderid", "");
		String money = Conet.TrackingIOSP.getString("money", "0");
		/*
		 * TrackingIO.setPayment(orderid, "weixinpay", "CNY",
		 * Integer.parseInt(money));
		 */
		/* if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
	            //...
	        }*/
		Log.d("51wan weixinpay", orderid + money);
		if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
			WanCommonSdk.getPayupCompleteCallBack().onComplete(resp.errCode); // 返回充值结果
//			ReYunTrack.setPayment(orderid, "weixinpay", "CNY",
//					Integer.parseInt(money));
			Toast.makeText(Conet.getmActivity(), "支付成功", Toast.LENGTH_SHORT)
					.show();
		} else {
//			Toast.makeText(Conet.getmActivity(), "支付失败", Toast.LENGTH_SHORT)
//					.show();
//			WanCommonSdk.getPayupCompleteCallBack().onComplete(1);// 返回充值结果
		}
		Conet.getInstance().exit();
		finish();
	}
}